import { reqBannerList, reqCategoryList, reqFloorList } from '@/api'
//小仓库

//1.存放数据
let state = {
  //商品分类的数据
  category: [],
  banner: [],
  floor: []
}

//2.修改数据
let mutations = {
  GETCATEGORY(state, category) {
    state.category = category
  },

  GETBANNER(state, banner) {
    state.banner = banner
  },

  GETFLOOR(state,floor){
    state.floor=floor
  }
}

//3.处理业务逻辑
let actions = {
  //商品分类的actions
  async getCategory({ commit, state, dispatch }) {
    //获取数据,保存在仓库中
    let result = await reqCategoryList()
    if (result.code == 200) {
      commit('GETCATEGORY', result.data)
    }
  },

  //轮播图
  async getBanner({ commit }) {
    let result = await reqBannerList()
    if (result.code == 200) {
      commit('GETBANNER', result.data)
    }
  },

  //商品楼层
  async getFloor({ commit }) {
    let result = await reqFloorList()
    if(result.code===200){
      commit('GETFLOOR',result.data)
    }
  }
}

//4.仓库计算属性
let getters = {}

//导出
export default {
  state,
  mutations,
  actions,
  getters
}
